//
//  SetHvacTimerApi.m
//  AFNetworking
//
//  Created by Henry on 2023/3/8.
//

#import "SetHvacTimerApi.h"
@interface SetHvacTimerApi()

@property(nonatomic,strong)NSMutableArray * timer_list;
@property(nonatomic,assign)long week;

@end
@implementation SetHvacTimerApi

-(id)initWithDevId:(NSString *)thingName withTemp:(NSMutableArray <TimerModel *>*)timer_list withWeek:(long)week withThingTypeName:(NSString *)thingTypeName{
    if(self = [super init]){
        self.thingName = thingName;
        self.timer_list = timer_list;
        self.week =week;
        self.thingTypeName = thingTypeName;
    }
    return self;
}


-(id)getTopic{
    return [NSString stringWithFormat:@"$aws/things/%@/shadow/name/%@/update",self.thingName,self.thingTypeName];
}

-(id)getCommandContent{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    NSMutableArray *list_1 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_2 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_3 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_4 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_5 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_6 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_7 = [[NSMutableArray alloc] init];
    
    [self.timer_list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        TimerModel *model = obj;
        NSString *de = [model.Timer
                        stringByReplacingOccurrencesOfString:@":" withString:@""];
        NSNumber *time = [NSNumber numberWithInt:[de intValue]];
            NSDictionary *dic=@{@"Timer":time,@"Mode":model.Mode};
        
        switch([model.Week intValue]){
            case 2:
                [list_2 addObject:dic];
                break;
            case 3:
                [list_3 addObject:dic];
                break;
            case 4:
                [list_4 addObject:dic];
                break;
            case 5:
                [list_5 addObject:dic];
                break;
            case 6:
                [list_6 addObject:dic];
                break;
            case 7:
                [list_7 addObject:dic];
                break;
            default:
                [list_1 addObject:dic];
                break;
        }
          
    }];
    
    switch(self.week){
        case 1:
            [dic addEntriesFromDictionary:@{@"Monday":list_1}];
            break;
        case 2:
            [dic addEntriesFromDictionary:@{@"Tuesday":list_2}];
            break;
        case 3:
            [dic addEntriesFromDictionary:@{@"Wednesday":list_3}];
            break;
        case 4:
            [dic addEntriesFromDictionary:@{@"Thursday":list_4}];
            break;
        case 5:
            [dic addEntriesFromDictionary:@{@"Friday":list_5}];
            break;
        case 6:
            [dic addEntriesFromDictionary:@{@"Saturday":list_6}];
            break;
        case 7:
            [dic addEntriesFromDictionary:@{@"Sunday":list_7}];
            break;
    }
    
    
    return @{@"state":@{@"desired":@{@"DevConfig":@{@"TimerTask":dic}}}};
}

-(id)getSubcribeTopic{
    return [NSString stringWithFormat:@"$aws/things/%@/shadow/name/%@/update/accepted",self.thingName,self.thingTypeName];
}
@end
